import java.awt.Image;
import java.util.ArrayList;

public abstract class Map {
	public static enum Levelname{LevelOne, LevelTwo};
	public Levelname levelname;
	protected ArrayList<Mimics> mimics = new ArrayList<Mimics>();
	protected ArrayList<MapItems> mapitems = new ArrayList<MapItems>();
	protected ArrayList<Background> backgrounds = new ArrayList<Background>();
    protected ArrayList<Rect> rects = new ArrayList<Rect>();
    protected Image collisionMap;
	protected int mapWidth, mapHeight, avatarSpawnPointX, avatarSpawnPointY;

	public Image getCollisionMap() {
		return collisionMap;
	}
	
	public int getMapWidth() {
		return mapWidth;
	}
	
	public int getMapHeight() {
		return mapHeight;
	}
	
	public int getAvatarSpawnPointX() {
		return avatarSpawnPointX;
	}
	
	public int getAvatarSpawnPointY() {
		return avatarSpawnPointY;
	}
	
	abstract void tickIntern(long delta);
	
	public void tick(long delta){
		
		for(Mimics m : mimics){
			m.update(delta);
			if(m.enemy || m.platform1 || m.platform2 || m.coconut){
				m.setX(m.getX() + m.getVelocityX());
				m.setY(m.getY() + m.getVelocityY());
				for(Rect r : rects){
					if(m.getBounds().intersects(r.getBounds())){
						switch(r.getDir()){
						case Rect.LEFT:
							m.setVelocityX(r.getSpeed());
							m.setVelocityY(0);
							m.setDir(Sprite.left);
							break;
						case Rect.RIGHT:
							m.setVelocityX(r.getSpeed());
							m.setVelocityY(0);
							m.setDir(Sprite.right);
							break;
						case Rect.UP:
							m.setVelocityY(r.getSpeed());
							m.setVelocityX(0);
							break;
						case Rect.DOWN:
							m.setVelocityY(r.getSpeed());
							m.setVelocityX(0);
							break;
						}//switch
					}//if
				}//for
			}//if
		}//for
		tickIntern(delta);
	}//void
	
	public MapItems getMapItemByType(MapItems.ItemType iType){
		for(MapItems mi : mapitems){
			if( mi.itemtype == iType ){
				return mi;
			}//if
		}//for
		return null;
	}//map
	
	public Mimics getMimicByPowerupType(Mimics.PowerupType type){
		for(Mimics m : mimics){
			if( m.powerup && m.powerupType == type ){
				return m;
			}//if
		}//for
		return null;
	}//mimics

	public ArrayList<Mimics> getList() {
		return mimics;
	}
	
	public ArrayList<MapItems> getItemList() {
		return mapitems;
	}

	public ArrayList<Background> getBackgrounds() {
		return backgrounds;
	}
	
	public ArrayList<Rect> getRects(){
		return rects;
	}
}//class
